/*
 * @Author: 小瓶子
 * @Date: 2025-05-26
 * @LastEditors: 小瓶子
 * @LastEditTime: 2025-06-10
 * @Description: Vue2 + Vite 路由配置
 */
import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

const routes = [
  {
    path: "/",
    name: "Home",
    component: () =>
      import(/* webpackChunkName: "home" */ "@/views/home/index.vue"),
  },
  {
    path: "*",
    redirect: "/", // 或指定专门的404页面
  },
];

const router = new Router({
  mode: "history",
  base: import.meta.env.BASE_URL,
  routes,
  // 可选：滚动行为控制
  scrollBehavior(to, from, savedPosition) {
    return savedPosition || { x: 0, y: 0 };
  },
});

// 可选：路由守卫
router.beforeEach((to, from, next) => {
  document.title = to.meta.title || "默认标题";
  next();
});

export default router;
